$(document).ready(function() {
    initHistoryScoring( historyScoring );
    initCurrentScoring( currentScoring );
});
function autoSubmitMe(el){
    if($(el).length && $(el).parents('form').length)
        $(el).parents('form').submit();
}
function initCurrentScoring(options){
    new Highcharts.Chart({
        chart: {
            renderTo: options.container,
            zoomType: 'xy',
            marginBottom: 70
        },
        credits:{
            enabled:false
        },
        title: {
            text: options.title
        },
        subtitle: {
            text: options.subTitleText
        },
        xAxis: [{
            categories: ['Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin','Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre']
        }],
        yAxis: [
        { // Primary yAxis
            labels: {
                style: {
                    color: '#89A54E'
                }
            },
            title: {
                text: options.yAxisTitle1,
                style: {
                    color: '#89A54E'
                }
            }
        }, 
        { // Secondary yAxis
            title: {
                text: options.yAxisTitle2,
                style: {
                    color: '#4572A7'
                }
            },
            labels: {
                style: {
                    color: '#4572A7'
                }
            },
            opposite: true
        }],
            
        tooltip: {
            formatter: function() {
                return ''+
                this.x +' '+options.year+' : '+ this.y +
                (this.series.color == '#89A54E' ? ' '+options.moneyUnit : ' '+options.volumeUnit);
            }
        },
        legend: {
            align: 'left',
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: [{
            name: options.weightAvgCostName,
            color: '#89A54E',
            type: 'spline',
            yAxis: 0,
            data: options.weightAvgCost
    
        }, {
            name: options.avgVolumeName,
            color: '#4572A7',
            type: 'spline',
            yAxis: 1,
            data: options.avgVolume
        }]
    });
}
function initHistoryScoring(options){
    new Highcharts.Chart({
        chart: {
            renderTo: options.container,
            zoomType: 'xy',
            marginBottom: 70
        },
        credits:{
            enabled:false
        },
        title: {
            text: options.titleText
        },
        subtitle: {
            text: options.subTitleText
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%e. %b',
                year: '%b'
            }
        },
        yAxis: [
        { // Primary yAxis
            labels: {
                style: {
                    color: '#89A54E'
                }
            },
            title: {
                text: options.yAxisTitle1,
                style: {
                    color: '#89A54E'
                }
            }
        }, 
        { // Secondary yAxis
            title: {
                text: options.yAxisTitle2,
                style: {
                    color: '#4572A7'
                }
            },
            labels: {
                style: {
                    color: '#4572A7'
                }
            },
            opposite: true
        }],
            
        tooltip: {
            formatter: function() {
                return ''+
                '<b>'+Highcharts.dateFormat('Date de relevé : %d/%m/%Y, %H:%M:%S', this.x) +'</b><br/>'+ this.y +
                (this.series.name == options.weightAvgCostName ? ' '+options.moneyUnit : ' '+options.volumeUnit);
            }
        },
        legend: {
            align: 'left',
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: [{
            name: options.weightAvgCostName,
            color: '#89A54E',
            type: 'spline',
            yAxis: 0,
            data: options.weightAvgCost
    
        }, {
            name: options.avgVolumeName,
            color: '#4572A7',
            type: 'spline',
            yAxis: 1,
            data: options.avgVolume
        }]
    });
}